/*
 *  Copyright 2012 Dirk Vranckaert
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package eu.vranckaert.vvl.utils.context;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Handler;

/**
 * User: DIRK VRANCKAERT
 * Date: 1/03/12
 * Time: 15:09
 */
public class NotificationUtil {
    Context ctx;
    
    private NotificationUtil(Context ctx) {
        this.ctx = ctx;
    }
    
    public static NotificationUtil getInstance(Context ctx) {
        return new NotificationUtil(ctx);
    }
    
    private void clearLedLight() {
        NotificationManager nm = (NotificationManager) ctx.getSystemService(ctx.NOTIFICATION_SERVICE);
        nm.cancel(9888);
    }

    private Runnable ClearLedTask = new Runnable() {
        public void run() {
            synchronized(ctx.getClass()) {
                clearLedLight();
            }
        }
    };

    public void flashLedLight() {
        NotificationManager nm = (NotificationManager) ctx.getSystemService(ctx.NOTIFICATION_SERVICE);
        Notification notif = new Notification();
        notif.ledARGB = 0xff2e525a;
        notif.flags = Notification.FLAG_SHOW_LIGHTS;
        notif.ledOnMS = 100;
        notif.ledOffMS = 100;
        nm.notify(9888, notif);
        // Program the end of the light :
        Handler mCleanLedHandler = new Handler();
        mCleanLedHandler.postDelayed(ClearLedTask, Constants.Time.ONE_MINUTE_MS);
    }
}
